# from itertools import combinations
# # 玩家数据
# players = {
#     'Player1': {'Warrior': 80, 'Mage': 20},
#     'Player2': {'Warrior': 30, 'Mage': 70},
#     'Player3': {'Warrior': 60, 'Mage': 40},
#     'Player4': {'Warrior': 40, 'Mage': 60}
# }

# #获取每个玩家的综合实力
# player_scores = {}
# for name, skills in players.items():
#     player_scores[name] = sum(skills.values())
# print(player_scores)

# #获取所有玩家的名字
# players_name = list(players.keys())

# #找出所有的组合，找差距最小的
# best_teams = None
# min_diff = float('inf') #初始化为无穷大，因为要找差距最小的队伍

# #找出所有可能的两对组合
# for team1 in combinations(players_name, 2):
#     for p in players_name:
#         if p not in team1:
#             team2 = [p]
# #计算出两队各自实力
#     team1_score = sum(player_scores[p] for p in team1)
#     team2_score = sum(player_scores[p] for p in team2)
#     #计算两队实力差距
#     diff = abs(team1_score - team2_score)
#     if diff < min_diff:
#         min_diff = diff
#         best_teams = (team1, team2, team1_score, team2_score)
# #输出最佳分组方案
# print(f'队伍1{best_teams[0]},综合实力:{best_teams[2]}')
# print(f'队伍2{best_teams[1]},综合实力:{best_teams[3]}')
# print(f'实力差距{min_diff}')


#餐厅菜品搭配分析
# 菜品分类信息
# menu_categories = {
#     '主菜': {'牛排', '披萨', '寿司'},
#     '配菜': {'薯条', '沙拉', '烤蔬菜'},
#     '饮品': {'可乐', '咖啡', '果汁'}
# }
# #将字典中这三种菜的值都转化为列表，为组合做准备
# for meau, course in menu_categories.items():
#     if meau == '主菜':
#         zhucai = list(course)
#     elif meau == '配菜':
#         peicai = list(course)
#     else:
#         yinpin = list(course)
# #创建组合列表，存放菜的搭配
# zuhe = []
# count = 0
# for z in zhucai:
#     for p in peicai:
#         for y in yinpin:
#             zuhe.append([z, p, y])
            
# #打印所有搭配
# for i in zuhe:
#     count += 1
#     print(count, end = " :")
#     for j in i:
#         print(j, end = ' ')
#     print()

#科研项目人员分配优化

# # 项目及技能需求
# projects = {
#     'ProjectA': {'Python', '数据分析', '机器学习'},
#     'ProjectB': {'Java', '数据库管理', '算法设计'},
#     'ProjectC': {'C++', '图像处理', '计算机视觉'}
# }
# # 人员及具备技能
# researchers = {
#     'Researcher1': {'Python', '数据分析'},
#     'Researcher2': {'Java', '数据库管理'},
#     'Researcher3': {'C++', '图像处理'},
#     'Researcher4': {'机器学习', '算法设计', '计算机视觉'}
# }
# assignments = {}
# #遍历人员和项目所需要的技能
# for project, skills_need in projects.items():
#     for name, skills in researchers.items():
#         #如果人的技能跟项目所需技能有交集，就把这个人安排在这个项目里
#         if skills & skills_need:
#             if project not in assignments:
#                 assignments[project] = []
#             assignments[project].append(name)
# for project, team in assignments.items():
#     print(f'{project}:{team}')


# 项目及技能需求
# projects = {
#     'ProjectA': {'Python', '数据分析', '机器学习'},
#     'ProjectB': {'Java', '数据库管理', '算法设计'},
#     'ProjectC': {'C++', '图像处理', '计算机视觉'}
# }
# # 人员及具备技能
# researchers = {
#     'Researcher1': {'Python', '数据分析'},
#     'Researcher2': {'Java', '数据库管理'},
#     'Researcher3': {'C++', '图像处理'},
#     'Researcher4': {'机器学习', '算法设计', '计算机视觉'}
# }
# #先创建一个字典存放项目和其对应所需的人员
# assignments = {}
# for project, skills_need in projects.items():
#     for name, skills in researchers.items():
#         #人员的技能是否满足判断项目所需技能
#         if skills_need & skills:
#             if project not in assignments:
#                 assignments[project] = []
#             assignments[project].append(name)
# #输出项目匹配结果
# for project, team in assignments.items():
#     print(f'{project}:{team}')

# 好友关系表
friendships = {
    'Alice': {'Bob', 'Charlie', 'David'},
    'Bob': {'Alice', 'Charlie'},
    'Charlie': {'Alice', 'Bob', 'David'},
    'David': {'Alice', 'Charlie'}
}
#存放人名和其对应是其他好友的次数
friend = {}
for friends_lst in friendships.values():
    for friends in friends_lst:
        if friends not in friend:
            friend[friends] = 0
        friend[friends] += 1
for name, count in friend.items():
    if count == len(friend) - 1:
        print(name)


